package com.haier.npt.page;

import java.io.Serializable;
import java.util.List;

import com.baomidou.mybatisplus.plugins.Page;

/**
 * @Description:分页查询结果集 
 * @author: lixu
 * @date:   2018年7月13日 下午3:15:55   
 * @param <T>
 */
public class PageBean<T> implements Serializable {

	private static final long serialVersionUID = -7044385380689727092L;

	public PageBean(List<T> records, int totalCount, int totalPage, int currentPage, int pageSize) {
		super();
		this.records = records;
		this.totalCount = totalCount;
		this.totalPage = totalPage;
		this.currentPage = currentPage;
		this.pageSize = pageSize;
	}
	
	/**
	 * 数据集
	 */
	private transient List<T> records;
	
	/**
	 * 数据总条数
	 */
	private int totalCount;
	
	/**总页数
	 * 
	 */
	private int totalPage;

	/**
	 * 当前页数
	 */
	private int currentPage;

	/**
	 * 每页数据条数
	 */
	private int pageSize;

	public int getPageSize() {
		return pageSize;
	}

	public int getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}
	

	public List<T> getRecords() {
		return records;
	}

	public void setRecords(List<T> records) {
		this.records = records;
	}

	public PageBean() {
	}



	public int getTotalCount() {
		return totalCount;
	}

	public void setTotalCount(int totalCount) {
		this.totalCount = totalCount;
	}

	public int getTotalPage() {
		return totalPage;
	}

	public void setTotalPage(int totalPage) {
		this.totalPage = totalPage;
	}

	public static <X> PageBean<X> toPageBean(Page<X> page) {
		PageBean<X> pageBean = new PageBean<>() ; 
		//设置当前页数
		pageBean.setCurrentPage(page.getCurrent());
		//设置数据
		pageBean.setRecords(page.getRecords());
		//设置每页条数
		pageBean.setPageSize(page.getSize());
		//设置总条数
		pageBean.setTotalCount(page.getTotal());
		//设置总页数
		pageBean.setTotalPage(page.getPages());
		return pageBean;
	}
}
